cmake_minimum_required(VERSION 3.15)

project(QBci)

# QT env configuration
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt5 COMPONENTS 
    Core 
    Network
    SerialPort
    REQUIRED
)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS 
    Core 
    Network
    SerialPort
    REQUIRED
)

find_package(OpenBLAS REQUIRED)
if(${OpenBLAS_FOUND})
    message("FOUND OpenBLAS")
else()
    message("NOT FOUND OpenBLAS")
endif()
find_package(RapidJSON REQUIRED)
find_package(Armadillo CONFIG REQUIRED)
find_package(SigPack REQUIRED)
if("MSVC" STREQUAL ${CMAKE_CXX_COMPILER_ID})
else()
    find_library(GFORTRAN_LIBRARY NAMES libgfortran.so)
    ## TODO 如何能够有移植性的添加libgfortran
    if(NOT GFORTRAN_LIBRARY)
        message("Not found GFORTRAN_LIBRARY")
        set(GFORTRAN_LIBRARY "-lgfortran")
    endif()
endif()

add_library(QBci STATIC
    src/qbci.cpp
    include/qbci.h
    include/QBci
    include/qbciglobal.h
    include/QBciGlobal
    src/qbcisignal.cpp
    include/qbcisignal.h
    src/qbcimod.cpp
    include/qbcimod.h
    include/QBciMod
    src/qbcisource.cpp
    include/qbcisource.h
    include/QBciSource
    src/qbcianalyzer.cpp
    include/QBciConfig
    include/qbciconfig.h
    src/qbciconfig.cpp
    include/QBciMath
    include/qbcimath.h
    src/qbcimath.cpp
    include/qbcianalyzer.h
    include/QBciAnalyzer
    include/qbciapp.h
    include/QBciApp
)
add_library(utils::QBci ALIAS QBci )

add_definitions(-DARMA_DONT_USE_WRAPPER)

target_include_directories(QBci
    PUBLIC
    ${PROJECT_SOURCE_DIR}/include
    Qt${QT_VERSION_MAJOR}::Core
    Qt${QT_VERSION_MAJOR}::Network
    utils::QLogger
    ${OpenBLAS_INCLUDE_DIRS}
    ${RapidJSON_INCLUDE_DIRS}
    ${SigPack_INCLUDE_DIRS}
    ${Armadillo_INCLUDE_DIRS}
)
target_link_libraries(QBci
    PUBLIC
    Qt${QT_VERSION_MAJOR}::Core
    Qt${QT_VERSION_MAJOR}::Network
    Qt${QT_VERSION_MAJOR}::SerialPort
    ${OpenBLAS_LIBRARIES}
    utils::QLogger
#    -O2 blas lapack
    ${GFORTRAN_LIBRARY}
)

#add_subdirectory(example)